home *** CD-ROM | disk | FTP | other *** search
/ Internet Info 1993 / Internet Info CD-ROM (Walnut Creek) (1993).iso / networking / terms / tipx / hunt.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-11  |  3.1 KB  |  122 lines

  1. /*
  2.  * Copyright (c) 1983 The Regents of the University of California.
  3.  * All rights reserved.
  4.  *
  5.  * Redistribution and use in source and binary forms are permitted
  6.  * provided that the above copyright notice and this paragraph are
  7.  * duplicated in all such forms and that any documentation,
  8.  * advertising materials, and other materials related to such
  9.  * distribution and use acknowledge that the software was developed
  10.  * by the University of California, Berkeley.  The name of the
  11.  * University may not be used to endorse or promote products derived
  12.  * from this software without specific prior written permission.
  13.  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14.  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15.  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16.  */
  17.  
  18. #ifndef lint
  19. static char sccsid[] = "@(#)hunt.c    5.4 (Berkeley) 9/2/88";
  20. #endif /* not lint */
  21.  
  22. #include "tip.h"
  23.  
  24. extern char *getremote();
  25. extern char *rindex();
  26.  
  27. static    jmp_buf deadline;
  28. static    int deadfl;
  29.  
  30. char uucplock[BUFSIZ];
  31. #ifdef TIPX
  32. char opened_tty[128];
  33. #endif
  34.  
  35. dead()
  36. {
  37.  
  38.     deadfl = 1;
  39.     longjmp(deadline, 1);
  40. }
  41.  
  42. hunt(name)
  43.     char *name;
  44. {
  45.     register char *cp, *cf, *ct;
  46.     sigfunc_t (*f)();
  47.  
  48.     f = signal(SIGALRM, dead);
  49.     while (cp = getremote(name)) {
  50.         /*
  51.          * The name of the lock is pretty important. We don't
  52.          * want to introduce the following security problems:
  53.          * 1. Namecollision in lock file between different devices
  54.          * 2. uucplock is used to decide whether or not to call
  55.          *    acucntrl. Thus, non-/dev devices should have a different
  56.          *    lock name than devices in /dev.
  57.          */
  58.         if (*cp != '/')    /* device name must be absolute path */
  59.             continue;
  60.         while (*cp == '/') cp++;
  61.         cp--;
  62.         if (strncmp("/dev/", cp, 5) == 0) {
  63.             cf = cp + 5;
  64.             while (*cf == '/') cf++;
  65.         } else
  66.             cf = cp;
  67.         ct = uucplock;
  68.         while (*cf) {
  69.             if (*cf == '/') {
  70.                 if (ct == uucplock
  71.                     || (ct > uucplock && *(ct-1) != '_'))
  72.                     *ct++ = '_';
  73.             } else
  74.                 *ct++ = *cf;
  75.             cf++;
  76.         }
  77.         *ct = '\0';
  78.         /*
  79.          * At this point we are guranteed that any devices outside
  80.          * /dev will have a lock name starting with underscore (_),
  81.          * and that any slashes (/) in the pathname have been changed
  82.          * to underscores, and that multiple slashes are only made
  83.          * into a single underscore. Thus, any way of expressing
  84.          * a pathname will lead to a unique lock file name.
  85.          */
  86.         deadfl = 0;
  87.         if (uu_lock(uucplock) < 0)
  88.             continue;
  89.         /*
  90.          * Straight through call units, such as the BIZCOMP,
  91.          * VADIC and the DF, must indicate they're hardwired in
  92.          *  order to get an open file descriptor placed in FD.
  93.          * Otherwise, as for a DN-11, the open will have to
  94.          *  be done in the "open" routine.
  95.          */
  96.         if (!HW)
  97.             break;
  98.  
  99. #ifdef TIPX
  100.         strcpy(opened_tty,cp);
  101. #endif
  102.         if (setjmp(deadline) == 0) {
  103.             alarm(10);
  104.             FD = open(cp, O_RDWR);
  105.         }
  106.         alarm(0);
  107.         if (FD < 0) {
  108.             perror(cp);
  109.             deadfl = 1;
  110.         }
  111.         if (!deadfl) {
  112.             ioctl(FD, TIOCEXCL, 0);
  113.             ioctl(FD, TIOCHPCL, 0);
  114.             signal(SIGALRM, SIG_DFL);
  115.             return ((int)cp);
  116.         }
  117.         (void)uu_unlock(uucplock);
  118.     }
  119.     signal(SIGALRM, f);
  120.     return (deadfl ? -1 : (int)cp);
  121. }
  122.